package cn.com.dycc.topic_activity.controller;

import java.io.UnsupportedEncodingException;


import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.com.dycc.common.controller.BaseController;

import cn.com.dycc.topic_activity.param.Pb_Special_ActivityParam;
import cn.com.dycc.topic_activity.service.Pb_Special_ActivityNotFoundException;
import cn.com.dycc.topic_activity.service.Pb_Special_ActivityService;
import cn.com.dycc.util.JsonObjectResult;


@Controller
@RequestMapping("/topic_activity/pb_special_activity")
public class Pb_Special_ActivityController extends BaseController{
	
	@Resource
	private Pb_Special_ActivityService pb_Special_ActivityService;
	
	/**
	 * 新增专题活动发起信息
	 * @param param
	 * @param session
	 * @param request
	 * @return
	 */
	@RequestMapping("/add.do")
	@ResponseBody
	public JsonObjectResult addPb_Special_Activity(Pb_Special_ActivityParam param,HttpSession session,HttpServletRequest request){
		
		int d=pb_Special_ActivityService.addPb_Special_Activity(param,request);
		String flag="成功导入数据条数为:"+d;
		
		return new JsonObjectResult(flag);		
	}
	/**
	 * 更新专题活动发起信息
	 * @param param
	 * @param request
	 * @param session
	 * @return
	 */
	@RequestMapping("/update.do")
	@ResponseBody
	public JsonObjectResult updatePb_Special_Activity(Pb_Special_ActivityParam param,HttpServletRequest request,HttpSession session){
		
		int d=pb_Special_ActivityService.updatePb_Special_Activity(param,request);
		String flag="成功更新数据条数为:"+d;
		return new JsonObjectResult(flag);
	}
	
	/**
	 * 删除专题活动发起信息
	 * @param request
	 * @return
	 */
	@RequestMapping("/delete.do")
	@ResponseBody
	public JsonObjectResult deletePb_Special_Activity(HttpServletRequest request){
		String []attrStrs=request.getParameterValues("activity_id");
		int d=pb_Special_ActivityService.deletePb_Special_Activity(attrStrs,request);
		String flag="成功删除数据条数为:"+d;
		return new JsonObjectResult(flag);
	}
	
	/**
	 * 查询关联自己所属党组织的专题活动发起信息
	 * @param param
	 * @param session
	 * @param request
	 * @return
	 * @throws UnsupportedEncodingException
	 */
	@RequestMapping("/join.do")
	@ResponseBody
	public JsonObjectResult findJoinPb_Special_Activity(Pb_Special_ActivityParam param,HttpSession session,HttpServletRequest request) throws UnsupportedEncodingException{
		String dept_id=(String)session.getAttribute("dept_id");
		param.setRelated_dept(dept_id);
		
		JsonObjectResult result=pb_Special_ActivityService.findPb_Special_ActivityByParam(param,request);
		
		return result;
	}
	/**
	 * 查询自己创建的专题活动发起信息
	 * @param param
	 * @param session
	 * @param request
	 * @return
	 * @throws UnsupportedEncodingException
	 */
	@RequestMapping("/list.do")
	@ResponseBody
	public JsonObjectResult findPb_Special_Activity(Pb_Special_ActivityParam param,HttpSession session,HttpServletRequest request) throws UnsupportedEncodingException{
		String id=(String)session.getAttribute("id");
		param.setOpt_user_id(id);
		
		JsonObjectResult result=pb_Special_ActivityService.findPb_Special_ActivityByParam(param,request);
		
		return result;
	}
	
	/**
	 * 查询有关自己所属党组织及子孙节点的党组织的专题活动发起信息
	 * @param param
	 * @param session
	 * @param request
	 * @return
	 * @throws UnsupportedEncodingException
	 */
	@RequestMapping("/listAll.do")
	@ResponseBody
	public JsonObjectResult findAllPb_Special_Activity(Pb_Special_ActivityParam param,HttpSession session,HttpServletRequest request) throws UnsupportedEncodingException{
		param.setLeader_flag("1");
		
		JsonObjectResult result=pb_Special_ActivityService.findPb_Special_ActivityByParam(param,request);
		
		return result;
	}
	
	/**
	 * 统计关联自己所属党组织的专题活动发起信息
	 * @param param
	 * @param session
	 * @param request
	 * @return
	 */
	@RequestMapping("/statistics.do")
	@ResponseBody
	public JsonObjectResult findSpecial_Activity_CountByParam(Pb_Special_ActivityParam param,HttpSession session,HttpServletRequest request) {
		
		String dept_id=(String)session.getAttribute("dept_id");
		param.setRelated_dept(dept_id);
		
		JsonObjectResult result=pb_Special_ActivityService.findSpecial_Activity_CountByParam(param, request);
		
		return result;
	}
	
	/**
	 * 统计关联自己所属党组织及子孙节点的党组织的专题活动发起信息(已发布)
	 * @param param
	 * @param session
	 * @param request
	 * @return
	 */
	@RequestMapping("/statisticsAll.do")
	@ResponseBody
	public JsonObjectResult findAllSpecial_Activity_CountByParam(Pb_Special_ActivityParam param,HttpSession session,HttpServletRequest request) {		
		
		param.setLeader_flag("1");
		
		JsonObjectResult result=pb_Special_ActivityService.findSpecial_Activity_CountByParam(param, request);		
		return result;
	}
	
	/**
	 * 查询专题活动发起信息详情
	 * @param param
	 * @param session
	 * @param request
	 * @return
	 * @throws UnsupportedEncodingException
	 */
	@RequestMapping("/detail.do")
	@ResponseBody
	public JsonObjectResult findDetailPb_Special_Activity(Pb_Special_ActivityParam param,HttpSession session,HttpServletRequest request) throws UnsupportedEncodingException{
		if(param.getActivity_id()==null||param.getActivity_id().trim().isEmpty()){
			throw new Pb_Special_ActivityNotFoundException("专题活动id不能为空");
		}
		
		JsonObjectResult result=pb_Special_ActivityService.findPb_Special_ActivityByParam(param,request);
		
		return result;
	}

}
